import sys
import dspy
from doubao import DoubaoLM
from tools import fetch_flight_info, fetch_itinerary, pick_flight, book_flight, cancel_itinerary, get_user_info, file_ticket
from tools import itinery_database


class DSPyAirlineCustomerSerice(dspy.Signature):
    """You are an airline customer service agent that helps user book and manage flights.

    You are given a list of tools to handle user request, and you should decide the right tool to use in order to
    fullfil users' request."""

    user_request: str = dspy.InputField()
    process_result: str = dspy.OutputField(
        desc=(
                "Message that summarizes the process result, and the information users need, e.g., the "
                "confirmation_number if a new flight is booked."
            )
        )


agent = dspy.ReAct(
    DSPyAirlineCustomerSerice,
    tools = [
        fetch_flight_info,
        fetch_itinerary,
        pick_flight,
        book_flight,
        cancel_itinerary,
        get_user_info,
        file_ticket,
    ]
)

dspy.configure(lm=DoubaoLM(api_key=sys.argv[1]))
result = agent(user_request="please help me book a flight from SFO to JFK on 09/01/2025, my name is Adam")
print("="*50)
print(result)

print("="*50)
print(itinery_database)

print("="*50)
dspy.inspect_history(n=10)
